package ua.kpi.transport.servlet.actions.saving;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import ua.kpi.transport.db.dao.factory.DAOFactory;
import ua.kpi.transport.db.dao.factory.DBEnum;
import ua.kpi.transport.db.dao.interfaces.IRouteDAO;
import ua.kpi.transport.db.entities.RouteBean;
import ua.kpi.transport.servlet.actions.IAction;
import ua.kpi.transport.servlet.actions.lists.RoutesListAction;

/**
 *
 * @author harker777
 */
public class SaveRouteAction implements IAction{

    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer id = Integer.valueOf(request.getParameter("id"));
        String name = request.getParameter("name");

        IRouteDAO rd = DAOFactory.getDAOFactory(DBEnum.MYSQL).getRouteDAO();
        RouteBean route = rd.find(id);
        route.setName(name);
        rd.update(route);
        
        return new RoutesListAction().execute(request, response);
    }
    
}
